using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Gadgets
{
    public partial class ChangePassword : Form
    {
        public ChangePassword()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!bValidateData())
            {
                return; 
            }
            if (!txtOldPass.Text.Equals(DeclareLibrary.PASSWORD))
            {
                ABSCommonLibrary.ShowMessage("Mat khau cu khong dung!");
                return; 
            }
            //String strPassword = txtNewPass.Text;                          
            //String sNewPassword = ABSCommonLibrary.EnCryptMD5(strPassword);   
            
            try
            {
                object[] p_param = new object[3]{
                    DeclareLibrary.USER_NAME, txtOldPass.Text.Trim(), txtNewPass.Text.Trim()};
                ABSCommonLibrary.DoExecute(CommonLibrary.CommonLibrary.BOSC020003, ref p_param).ToString();
                ABSCommonLibrary.ShowMessage("Mat khau da duoc thay doi");
                DeclareLibrary.PASSWORD = txtNewPass.Text.Trim();
                this.Close();  
                return; 
            }
            catch (Exception ex)
            {
                ABSCommonLibrary.ShowErrorMessage(ex.ToString());   
            }

        }
        private Boolean bValidateData()
        {
            if (txtOldPass.Text.Equals(String.Empty))
            {
                txtOldPass.Focus();
                ABSCommonLibrary.ShowMessage("Mat khau cu khong duoc phep trong");
                return false; 
            }
            if (txtNewPass.Text.Equals(String.Empty))
            {
                txtNewPass.Focus();
                ABSCommonLibrary.ShowMessage("Mat khau moi khong duoc phep trong");
                return false;
            }
            if (txtConfirm.Text.Equals(String.Empty))
            {
                txtConfirm.Focus();
                ABSCommonLibrary.ShowMessage("Xac nhan thay doi mat khau khong duoc phep trong");
                return false;
            }
            if (!txtNewPass.Text.Equals(txtConfirm.Text))
            {
                txtNewPass.Focus();
                ABSCommonLibrary.ShowMessage("Xac nhan mat khau khong trung nhau");
                return false;
            }
            return true; 
        }

    }
}